﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.IO;

namespace Copycat
{
    public static class MailSender
    {
        public static bool SendMail(string ToAddress, string Subject, string Body)
        {
            try
            {
                MailMessage mail = new MailMessage();

                mail.From = new MailAddress("gocopycat@yahoo.com");
                
                if (!ToAddress.Contains(','))
                    mail.To.Add(new MailAddress(ToAddress));
                else
                    mail.To.Add(ToAddress);
                
                mail.Subject = Subject;

                /*mail.Body = "<b>Name</b> : " + txtName.Text + "<br/>" + "<b>Mail</b> : " + txtEmail.Text
                   + "<br/>" + "<b>Tel. </b> : " + txtTel.Text +"<br/>" + "<b>Facebook Name </b> : " + txtFacebookName.Text+ "<br/><br/>";*/

                mail.Body = Body;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new System.Net.Mail.SmtpClient();
                smtp.Host = " smtp.mail.yahoo.com"; //Or Your SMTP Server Address
                smtp.Port = 587;
                smtp.Credentials = new System.Net.NetworkCredential
                     ("gocopycat@yahoo.com", "copycat_copycat");
                smtp.EnableSsl = false;
                smtp.Send(mail);

                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool SendMailWithAttachments(string senderName,string Discription,string FileName,Stream fileContent)
        {
            try
            {
                MailMessage mail = new MailMessage();

                mail.From = new MailAddress("gocopycat@yahoo.com");

                mail.To.Add(new MailAddress("cairolove2009@yahoo.com"));

                mail.Subject = "Print Request - " + senderName;

                mail.Attachments.Add(new Attachment(fileContent,FileName));

                mail.Body = Discription;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new System.Net.Mail.SmtpClient();
                smtp.Host = " smtp.mail.yahoo.com"; //Or Your SMTP Server Address
                smtp.Port = 587;
                smtp.Credentials = new System.Net.NetworkCredential
                     ("gocopycat@yahoo.com", "copycat_copycat");
                smtp.EnableSsl = false;
                smtp.Send(mail);

                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}